library(sjlabelled)

# Set working directory
setwd("SET_YOUR_PATH/NLSY97")


new_data <- read.table('nlsy97.dat', sep=' ')
names(new_data) <- c('R0000100',
  'R0531800',
  'R0531900',
  'R0532300',
  'R0532700',
  'R0532800',
  'R0533600',
  'R0535500',
  'R0536300',
  'R0536401',
  'R0536402',
  'R1201300',
  'R1204500',
  'R1204600',
  'R1205400',
  'R1235800',
  'R1302400',
  'R1302500',
  'R1302600',
  'R1302700',
  'R1482600',
  'R2563300',
  'R2563700',
  'R3884900',
  'R3885300',
  'R5464100',
  'R5464500',
  'R7227800',
  'R7228200',
  'S1541700',
  'S1542100',
  'S2011500',
  'S2011900',
  'S3812400',
  'S3813400',
  'S3823000',
  'S4921000',
  'S4921100',
  'S4921400',
  'S7509600',
  'S7513700',
  'S7513900',
  'S8645400',
  'S8645600',
  'S8645700',
  'S8645800',
  'T2015800',
  'T2016200',
  'T2016400',
  'T3161800',
  'T3162000',
  'T3162100',
  'T3162200',
  'T3162300',
  'T5206500',
  'T5206900',
  'T5207100',
  'T6215300',
  'T6215500',
  'T6215600',
  'T6215700',
  'T6215800',
  'Z9061400',
  'Z9061600',
  'Z9061800',
  'Z9061901',
  'Z9065201',
  'Z9065301',
  'Z9065401',
  'Z9083800',
  'Z9083900')


# Handle missing values

  new_data[new_data == -1] = NA  # Refused 
  new_data[new_data == -2] = NA  # Dont know 
  new_data[new_data == -3] = NA  # Invalid missing 
  new_data[new_data == -4] = NA  # Valid missing 
  new_data[new_data == -5] = NA  # Non-interview 


# If there are values not categorized they will be represented as NA

vallabels = function(data) {
  data$R0000100[1.0 <= data$R0000100 & data$R0000100 <= 999.0] <- 1.0
  data$R0000100[1000.0 <= data$R0000100 & data$R0000100 <= 1999.0] <- 1000.0
  data$R0000100[2000.0 <= data$R0000100 & data$R0000100 <= 2999.0] <- 2000.0
  data$R0000100[3000.0 <= data$R0000100 & data$R0000100 <= 3999.0] <- 3000.0
  data$R0000100[4000.0 <= data$R0000100 & data$R0000100 <= 4999.0] <- 4000.0
  data$R0000100[5000.0 <= data$R0000100 & data$R0000100 <= 5999.0] <- 5000.0
  data$R0000100[6000.0 <= data$R0000100 & data$R0000100 <= 6999.0] <- 6000.0
  data$R0000100[7000.0 <= data$R0000100 & data$R0000100 <= 7999.0] <- 7000.0
  data$R0000100[8000.0 <= data$R0000100 & data$R0000100 <= 8999.0] <- 8000.0
  data$R0000100[9000.0 <= data$R0000100 & data$R0000100 <= 9999.0] <- 9000.0
  data$R0000100 <- factor(data$R0000100, 
    levels=c(0.0,1.0,1000.0,2000.0,3000.0,4000.0,5000.0,6000.0,7000.0,8000.0,9000.0), 
    labels=c("0",
      "1 TO 999",
      "1000 TO 1999",
      "2000 TO 2999",
      "3000 TO 3999",
      "4000 TO 4999",
      "5000 TO 5999",
      "6000 TO 6999",
      "7000 TO 7999",
      "8000 TO 8999",
      "9000 TO 9999"))
  data$R0531800[20.0 <= data$R0531800 & data$R0531800 <= 99.0] <- 20.0
  data$R0531800 <- factor(data$R0531800, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0531900[20.0 <= data$R0531900 & data$R0531900 <= 99.0] <- 20.0
  data$R0531900 <- factor(data$R0531900, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0532300[20.0 <= data$R0532300 & data$R0532300 <= 99.0] <- 20.0
  data$R0532300 <- factor(data$R0532300, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0532700[20.0 <= data$R0532700 & data$R0532700 <= 99.0] <- 20.0
  data$R0532700 <- factor(data$R0532700, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0532800[20.0 <= data$R0532800 & data$R0532800 <= 99.0] <- 20.0
  data$R0532800 <- factor(data$R0532800, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0533600[20.0 <= data$R0533600 & data$R0533600 <= 99.0] <- 20.0
  data$R0533600 <- factor(data$R0533600, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0535500[20.0 <= data$R0535500 & data$R0535500 <= 99.0] <- 20.0
  data$R0535500 <- factor(data$R0535500, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R0536300 <- factor(data$R0536300, 
    levels=c(0.0,1.0,2.0), 
    labels=c("No Information",
      "Male",
      "Female"))
  data$R0536401 <- factor(data$R0536401, 
    levels=c(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0), 
    labels=c("1: January",
      "2: February",
      "3: March",
      "4: April",
      "5: May",
      "6: June",
      "7: July",
      "8: August",
      "9: September",
      "10: October",
      "11: November",
      "12: December"))
  data$R1201300 <- factor(data$R1201300, 
    levels=c(1.0,2.0,3.0), 
    labels=c("Citizen, born in the U.S.",
      "Unknown, not born in U.S.",
      "Unknown, can't determine birthplace"))
  data$R1204500[-999999.0 <= data$R1204500 & data$R1204500 <= -3000.0] <- -999999.0
  data$R1204500[-2999.0 <= data$R1204500 & data$R1204500 <= -2000.0] <- -2999.0
  data$R1204500[-1999.0 <= data$R1204500 & data$R1204500 <= -1000.0] <- -1999.0
  data$R1204500[-999.0 <= data$R1204500 & data$R1204500 <= -1.0] <- -999.0
  data$R1204500[1.0 <= data$R1204500 & data$R1204500 <= 1000.0] <- 1.0
  data$R1204500[1001.0 <= data$R1204500 & data$R1204500 <= 2000.0] <- 1001.0
  data$R1204500[2001.0 <= data$R1204500 & data$R1204500 <= 3000.0] <- 2001.0
  data$R1204500[3001.0 <= data$R1204500 & data$R1204500 <= 5000.0] <- 3001.0
  data$R1204500[5001.0 <= data$R1204500 & data$R1204500 <= 10000.0] <- 5001.0
  data$R1204500[10001.0 <= data$R1204500 & data$R1204500 <= 20000.0] <- 10001.0
  data$R1204500[20001.0 <= data$R1204500 & data$R1204500 <= 30000.0] <- 20001.0
  data$R1204500[30001.0 <= data$R1204500 & data$R1204500 <= 40000.0] <- 30001.0
  data$R1204500[40001.0 <= data$R1204500 & data$R1204500 <= 50000.0] <- 40001.0
  data$R1204500[50001.0 <= data$R1204500 & data$R1204500 <= 65000.0] <- 50001.0
  data$R1204500[65001.0 <= data$R1204500 & data$R1204500 <= 80000.0] <- 65001.0
  data$R1204500[80001.0 <= data$R1204500 & data$R1204500 <= 100000.0] <- 80001.0
  data$R1204500[100001.0 <= data$R1204500 & data$R1204500 <= 150000.0] <- 100001.0
  data$R1204500[150001.0 <= data$R1204500 & data$R1204500 <= 200000.0] <- 150001.0
  data$R1204500[200001.0 <= data$R1204500 & data$R1204500 <= 999999.0] <- 200001.0
  data$R1204500 <- factor(data$R1204500, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$R1204600 <- factor(data$R1204600, 
    levels=c(1.0,2.0), 
    labels=c("Parent",
      "Youth"))
  data$R1205400[20.0 <= data$R1205400 & data$R1205400 <= 99.0] <- 20.0
  data$R1205400 <- factor(data$R1205400, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R1235800 <- factor(data$R1235800, 
    levels=c(0.0,1.0), 
    labels=c("Oversample",
      "Cross-sectional"))
  data$R1302400 <- factor(data$R1302400, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,95.0), 
    labels=c("NONE",
      "1ST GRADE",
      "2ND GRADE",
      "3RD GRADE",
      "4TH GRADE",
      "5TH GRADE",
      "6TH GRADE",
      "7TH GRADE",
      "8TH GRADE",
      "9TH GRADE",
      "10TH GRADE",
      "11TH GRADE",
      "12TH GRADE",
      "1ST YEAR COLLEGE",
      "2ND YEAR COLLEGE",
      "3RD YEAR COLLEGE",
      "4TH YEAR COLLEGE",
      "5TH YEAR COLLEGE",
      "6TH YEAR COLLEGE",
      "7TH YEAR COLLEGE",
      "8TH YEAR COLLEGE OR MORE",
      "UNGRADED"))
  data$R1302500 <- factor(data$R1302500, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,95.0), 
    labels=c("NONE",
      "1ST GRADE",
      "2ND GRADE",
      "3RD GRADE",
      "4TH GRADE",
      "5TH GRADE",
      "6TH GRADE",
      "7TH GRADE",
      "8TH GRADE",
      "9TH GRADE",
      "10TH GRADE",
      "11TH GRADE",
      "12TH GRADE",
      "1ST YEAR COLLEGE",
      "2ND YEAR COLLEGE",
      "3RD YEAR COLLEGE",
      "4TH YEAR COLLEGE",
      "5TH YEAR COLLEGE",
      "6TH YEAR COLLEGE",
      "7TH YEAR COLLEGE",
      "8TH YEAR COLLEGE OR MORE",
      "UNGRADED"))
  data$R1302600 <- factor(data$R1302600, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,95.0), 
    labels=c("NONE",
      "1ST GRADE",
      "2ND GRADE",
      "3RD GRADE",
      "4TH GRADE",
      "5TH GRADE",
      "6TH GRADE",
      "7TH GRADE",
      "8TH GRADE",
      "9TH GRADE",
      "10TH GRADE",
      "11TH GRADE",
      "12TH GRADE",
      "1ST YEAR COLLEGE",
      "2ND YEAR COLLEGE",
      "3RD YEAR COLLEGE",
      "4TH YEAR COLLEGE",
      "5TH YEAR COLLEGE",
      "6TH YEAR COLLEGE",
      "7TH YEAR COLLEGE",
      "8TH YEAR COLLEGE OR MORE",
      "UNGRADED"))
  data$R1302700 <- factor(data$R1302700, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,95.0), 
    labels=c("NONE",
      "1ST GRADE",
      "2ND GRADE",
      "3RD GRADE",
      "4TH GRADE",
      "5TH GRADE",
      "6TH GRADE",
      "7TH GRADE",
      "8TH GRADE",
      "9TH GRADE",
      "10TH GRADE",
      "11TH GRADE",
      "12TH GRADE",
      "1ST YEAR COLLEGE",
      "2ND YEAR COLLEGE",
      "3RD YEAR COLLEGE",
      "4TH YEAR COLLEGE",
      "5TH YEAR COLLEGE",
      "6TH YEAR COLLEGE",
      "7TH YEAR COLLEGE",
      "8TH YEAR COLLEGE OR MORE",
      "UNGRADED"))
  data$R1482600 <- factor(data$R1482600, 
    levels=c(1.0,2.0,3.0,4.0), 
    labels=c("Black",
      "Hispanic",
      "Mixed Race (Non-Hispanic)",
      "Non-Black / Non-Hispanic"))
  data$R2563300[-999999.0 <= data$R2563300 & data$R2563300 <= -3000.0] <- -999999.0
  data$R2563300[-2999.0 <= data$R2563300 & data$R2563300 <= -2000.0] <- -2999.0
  data$R2563300[-1999.0 <= data$R2563300 & data$R2563300 <= -1000.0] <- -1999.0
  data$R2563300[-999.0 <= data$R2563300 & data$R2563300 <= -1.0] <- -999.0
  data$R2563300[1.0 <= data$R2563300 & data$R2563300 <= 1000.0] <- 1.0
  data$R2563300[1001.0 <= data$R2563300 & data$R2563300 <= 2000.0] <- 1001.0
  data$R2563300[2001.0 <= data$R2563300 & data$R2563300 <= 3000.0] <- 2001.0
  data$R2563300[3001.0 <= data$R2563300 & data$R2563300 <= 5000.0] <- 3001.0
  data$R2563300[5001.0 <= data$R2563300 & data$R2563300 <= 10000.0] <- 5001.0
  data$R2563300[10001.0 <= data$R2563300 & data$R2563300 <= 20000.0] <- 10001.0
  data$R2563300[20001.0 <= data$R2563300 & data$R2563300 <= 30000.0] <- 20001.0
  data$R2563300[30001.0 <= data$R2563300 & data$R2563300 <= 40000.0] <- 30001.0
  data$R2563300[40001.0 <= data$R2563300 & data$R2563300 <= 50000.0] <- 40001.0
  data$R2563300[50001.0 <= data$R2563300 & data$R2563300 <= 65000.0] <- 50001.0
  data$R2563300[65001.0 <= data$R2563300 & data$R2563300 <= 80000.0] <- 65001.0
  data$R2563300[80001.0 <= data$R2563300 & data$R2563300 <= 100000.0] <- 80001.0
  data$R2563300[100001.0 <= data$R2563300 & data$R2563300 <= 150000.0] <- 100001.0
  data$R2563300[150001.0 <= data$R2563300 & data$R2563300 <= 200000.0] <- 150001.0
  data$R2563300[200001.0 <= data$R2563300 & data$R2563300 <= 999999.0] <- 200001.0
  data$R2563300 <- factor(data$R2563300, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$R2563700[20.0 <= data$R2563700 & data$R2563700 <= 99.0] <- 20.0
  data$R2563700 <- factor(data$R2563700, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R3884900[-999999.0 <= data$R3884900 & data$R3884900 <= -3000.0] <- -999999.0
  data$R3884900[-2999.0 <= data$R3884900 & data$R3884900 <= -2000.0] <- -2999.0
  data$R3884900[-1999.0 <= data$R3884900 & data$R3884900 <= -1000.0] <- -1999.0
  data$R3884900[-999.0 <= data$R3884900 & data$R3884900 <= -1.0] <- -999.0
  data$R3884900[1.0 <= data$R3884900 & data$R3884900 <= 1000.0] <- 1.0
  data$R3884900[1001.0 <= data$R3884900 & data$R3884900 <= 2000.0] <- 1001.0
  data$R3884900[2001.0 <= data$R3884900 & data$R3884900 <= 3000.0] <- 2001.0
  data$R3884900[3001.0 <= data$R3884900 & data$R3884900 <= 5000.0] <- 3001.0
  data$R3884900[5001.0 <= data$R3884900 & data$R3884900 <= 10000.0] <- 5001.0
  data$R3884900[10001.0 <= data$R3884900 & data$R3884900 <= 20000.0] <- 10001.0
  data$R3884900[20001.0 <= data$R3884900 & data$R3884900 <= 30000.0] <- 20001.0
  data$R3884900[30001.0 <= data$R3884900 & data$R3884900 <= 40000.0] <- 30001.0
  data$R3884900[40001.0 <= data$R3884900 & data$R3884900 <= 50000.0] <- 40001.0
  data$R3884900[50001.0 <= data$R3884900 & data$R3884900 <= 65000.0] <- 50001.0
  data$R3884900[65001.0 <= data$R3884900 & data$R3884900 <= 80000.0] <- 65001.0
  data$R3884900[80001.0 <= data$R3884900 & data$R3884900 <= 100000.0] <- 80001.0
  data$R3884900[100001.0 <= data$R3884900 & data$R3884900 <= 150000.0] <- 100001.0
  data$R3884900[150001.0 <= data$R3884900 & data$R3884900 <= 200000.0] <- 150001.0
  data$R3884900[200001.0 <= data$R3884900 & data$R3884900 <= 999999.0] <- 200001.0
  data$R3884900 <- factor(data$R3884900, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$R3885300[20.0 <= data$R3885300 & data$R3885300 <= 99.0] <- 20.0
  data$R3885300 <- factor(data$R3885300, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R5464100[-999999.0 <= data$R5464100 & data$R5464100 <= -3000.0] <- -999999.0
  data$R5464100[-2999.0 <= data$R5464100 & data$R5464100 <= -2000.0] <- -2999.0
  data$R5464100[-1999.0 <= data$R5464100 & data$R5464100 <= -1000.0] <- -1999.0
  data$R5464100[-999.0 <= data$R5464100 & data$R5464100 <= -1.0] <- -999.0
  data$R5464100[1.0 <= data$R5464100 & data$R5464100 <= 1000.0] <- 1.0
  data$R5464100[1001.0 <= data$R5464100 & data$R5464100 <= 2000.0] <- 1001.0
  data$R5464100[2001.0 <= data$R5464100 & data$R5464100 <= 3000.0] <- 2001.0
  data$R5464100[3001.0 <= data$R5464100 & data$R5464100 <= 5000.0] <- 3001.0
  data$R5464100[5001.0 <= data$R5464100 & data$R5464100 <= 10000.0] <- 5001.0
  data$R5464100[10001.0 <= data$R5464100 & data$R5464100 <= 20000.0] <- 10001.0
  data$R5464100[20001.0 <= data$R5464100 & data$R5464100 <= 30000.0] <- 20001.0
  data$R5464100[30001.0 <= data$R5464100 & data$R5464100 <= 40000.0] <- 30001.0
  data$R5464100[40001.0 <= data$R5464100 & data$R5464100 <= 50000.0] <- 40001.0
  data$R5464100[50001.0 <= data$R5464100 & data$R5464100 <= 65000.0] <- 50001.0
  data$R5464100[65001.0 <= data$R5464100 & data$R5464100 <= 80000.0] <- 65001.0
  data$R5464100[80001.0 <= data$R5464100 & data$R5464100 <= 100000.0] <- 80001.0
  data$R5464100[100001.0 <= data$R5464100 & data$R5464100 <= 150000.0] <- 100001.0
  data$R5464100[150001.0 <= data$R5464100 & data$R5464100 <= 200000.0] <- 150001.0
  data$R5464100[200001.0 <= data$R5464100 & data$R5464100 <= 999999.0] <- 200001.0
  data$R5464100 <- factor(data$R5464100, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$R5464500[20.0 <= data$R5464500 & data$R5464500 <= 99.0] <- 20.0
  data$R5464500 <- factor(data$R5464500, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$R7227800[-999999.0 <= data$R7227800 & data$R7227800 <= -3000.0] <- -999999.0
  data$R7227800[-2999.0 <= data$R7227800 & data$R7227800 <= -2000.0] <- -2999.0
  data$R7227800[-1999.0 <= data$R7227800 & data$R7227800 <= -1000.0] <- -1999.0
  data$R7227800[-999.0 <= data$R7227800 & data$R7227800 <= -1.0] <- -999.0
  data$R7227800[1.0 <= data$R7227800 & data$R7227800 <= 1000.0] <- 1.0
  data$R7227800[1001.0 <= data$R7227800 & data$R7227800 <= 2000.0] <- 1001.0
  data$R7227800[2001.0 <= data$R7227800 & data$R7227800 <= 3000.0] <- 2001.0
  data$R7227800[3001.0 <= data$R7227800 & data$R7227800 <= 5000.0] <- 3001.0
  data$R7227800[5001.0 <= data$R7227800 & data$R7227800 <= 10000.0] <- 5001.0
  data$R7227800[10001.0 <= data$R7227800 & data$R7227800 <= 20000.0] <- 10001.0
  data$R7227800[20001.0 <= data$R7227800 & data$R7227800 <= 30000.0] <- 20001.0
  data$R7227800[30001.0 <= data$R7227800 & data$R7227800 <= 40000.0] <- 30001.0
  data$R7227800[40001.0 <= data$R7227800 & data$R7227800 <= 50000.0] <- 40001.0
  data$R7227800[50001.0 <= data$R7227800 & data$R7227800 <= 65000.0] <- 50001.0
  data$R7227800[65001.0 <= data$R7227800 & data$R7227800 <= 80000.0] <- 65001.0
  data$R7227800[80001.0 <= data$R7227800 & data$R7227800 <= 100000.0] <- 80001.0
  data$R7227800[100001.0 <= data$R7227800 & data$R7227800 <= 150000.0] <- 100001.0
  data$R7227800[150001.0 <= data$R7227800 & data$R7227800 <= 200000.0] <- 150001.0
  data$R7227800[200001.0 <= data$R7227800 & data$R7227800 <= 999999.0] <- 200001.0
  data$R7227800 <- factor(data$R7227800, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$R7228200[20.0 <= data$R7228200 & data$R7228200 <= 99.0] <- 20.0
  data$R7228200 <- factor(data$R7228200, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$S1541700[-999999.0 <= data$S1541700 & data$S1541700 <= -3000.0] <- -999999.0
  data$S1541700[-2999.0 <= data$S1541700 & data$S1541700 <= -2000.0] <- -2999.0
  data$S1541700[-1999.0 <= data$S1541700 & data$S1541700 <= -1000.0] <- -1999.0
  data$S1541700[-999.0 <= data$S1541700 & data$S1541700 <= -1.0] <- -999.0
  data$S1541700[1.0 <= data$S1541700 & data$S1541700 <= 1000.0] <- 1.0
  data$S1541700[1001.0 <= data$S1541700 & data$S1541700 <= 2000.0] <- 1001.0
  data$S1541700[2001.0 <= data$S1541700 & data$S1541700 <= 3000.0] <- 2001.0
  data$S1541700[3001.0 <= data$S1541700 & data$S1541700 <= 5000.0] <- 3001.0
  data$S1541700[5001.0 <= data$S1541700 & data$S1541700 <= 10000.0] <- 5001.0
  data$S1541700[10001.0 <= data$S1541700 & data$S1541700 <= 20000.0] <- 10001.0
  data$S1541700[20001.0 <= data$S1541700 & data$S1541700 <= 30000.0] <- 20001.0
  data$S1541700[30001.0 <= data$S1541700 & data$S1541700 <= 40000.0] <- 30001.0
  data$S1541700[40001.0 <= data$S1541700 & data$S1541700 <= 50000.0] <- 40001.0
  data$S1541700[50001.0 <= data$S1541700 & data$S1541700 <= 65000.0] <- 50001.0
  data$S1541700[65001.0 <= data$S1541700 & data$S1541700 <= 80000.0] <- 65001.0
  data$S1541700[80001.0 <= data$S1541700 & data$S1541700 <= 100000.0] <- 80001.0
  data$S1541700[100001.0 <= data$S1541700 & data$S1541700 <= 150000.0] <- 100001.0
  data$S1541700[150001.0 <= data$S1541700 & data$S1541700 <= 200000.0] <- 150001.0
  data$S1541700[200001.0 <= data$S1541700 & data$S1541700 <= 999999.0] <- 200001.0
  data$S1541700 <- factor(data$S1541700, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$S1542100[20.0 <= data$S1542100 & data$S1542100 <= 99.0] <- 20.0
  data$S1542100 <- factor(data$S1542100, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$S2011500[-999999.0 <= data$S2011500 & data$S2011500 <= -3000.0] <- -999999.0
  data$S2011500[-2999.0 <= data$S2011500 & data$S2011500 <= -2000.0] <- -2999.0
  data$S2011500[-1999.0 <= data$S2011500 & data$S2011500 <= -1000.0] <- -1999.0
  data$S2011500[-999.0 <= data$S2011500 & data$S2011500 <= -1.0] <- -999.0
  data$S2011500[1.0 <= data$S2011500 & data$S2011500 <= 1000.0] <- 1.0
  data$S2011500[1001.0 <= data$S2011500 & data$S2011500 <= 2000.0] <- 1001.0
  data$S2011500[2001.0 <= data$S2011500 & data$S2011500 <= 3000.0] <- 2001.0
  data$S2011500[3001.0 <= data$S2011500 & data$S2011500 <= 5000.0] <- 3001.0
  data$S2011500[5001.0 <= data$S2011500 & data$S2011500 <= 10000.0] <- 5001.0
  data$S2011500[10001.0 <= data$S2011500 & data$S2011500 <= 20000.0] <- 10001.0
  data$S2011500[20001.0 <= data$S2011500 & data$S2011500 <= 30000.0] <- 20001.0
  data$S2011500[30001.0 <= data$S2011500 & data$S2011500 <= 40000.0] <- 30001.0
  data$S2011500[40001.0 <= data$S2011500 & data$S2011500 <= 50000.0] <- 40001.0
  data$S2011500[50001.0 <= data$S2011500 & data$S2011500 <= 65000.0] <- 50001.0
  data$S2011500[65001.0 <= data$S2011500 & data$S2011500 <= 80000.0] <- 65001.0
  data$S2011500[80001.0 <= data$S2011500 & data$S2011500 <= 100000.0] <- 80001.0
  data$S2011500[100001.0 <= data$S2011500 & data$S2011500 <= 150000.0] <- 100001.0
  data$S2011500[150001.0 <= data$S2011500 & data$S2011500 <= 200000.0] <- 150001.0
  data$S2011500[200001.0 <= data$S2011500 & data$S2011500 <= 999999.0] <- 200001.0
  data$S2011500 <- factor(data$S2011500, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$S2011900[20.0 <= data$S2011900 & data$S2011900 <= 99.0] <- 20.0
  data$S2011900 <- factor(data$S2011900, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$S3812400[-999999.0 <= data$S3812400 & data$S3812400 <= -3000.0] <- -999999.0
  data$S3812400[-2999.0 <= data$S3812400 & data$S3812400 <= -2000.0] <- -2999.0
  data$S3812400[-1999.0 <= data$S3812400 & data$S3812400 <= -1000.0] <- -1999.0
  data$S3812400[-999.0 <= data$S3812400 & data$S3812400 <= -1.0] <- -999.0
  data$S3812400[1.0 <= data$S3812400 & data$S3812400 <= 1000.0] <- 1.0
  data$S3812400[1001.0 <= data$S3812400 & data$S3812400 <= 2000.0] <- 1001.0
  data$S3812400[2001.0 <= data$S3812400 & data$S3812400 <= 3000.0] <- 2001.0
  data$S3812400[3001.0 <= data$S3812400 & data$S3812400 <= 5000.0] <- 3001.0
  data$S3812400[5001.0 <= data$S3812400 & data$S3812400 <= 10000.0] <- 5001.0
  data$S3812400[10001.0 <= data$S3812400 & data$S3812400 <= 20000.0] <- 10001.0
  data$S3812400[20001.0 <= data$S3812400 & data$S3812400 <= 30000.0] <- 20001.0
  data$S3812400[30001.0 <= data$S3812400 & data$S3812400 <= 40000.0] <- 30001.0
  data$S3812400[40001.0 <= data$S3812400 & data$S3812400 <= 50000.0] <- 40001.0
  data$S3812400[50001.0 <= data$S3812400 & data$S3812400 <= 65000.0] <- 50001.0
  data$S3812400[65001.0 <= data$S3812400 & data$S3812400 <= 80000.0] <- 65001.0
  data$S3812400[80001.0 <= data$S3812400 & data$S3812400 <= 100000.0] <- 80001.0
  data$S3812400[100001.0 <= data$S3812400 & data$S3812400 <= 150000.0] <- 100001.0
  data$S3812400[150001.0 <= data$S3812400 & data$S3812400 <= 200000.0] <- 150001.0
  data$S3812400[200001.0 <= data$S3812400 & data$S3812400 <= 999999.0] <- 200001.0
  data$S3812400 <- factor(data$S3812400, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$S3813400[20.0 <= data$S3813400 & data$S3813400 <= 99.0] <- 20.0
  data$S3813400 <- factor(data$S3813400, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$S3823000 <- factor(data$S3823000, 
    levels=c(1.0,2.0,3.0,4.0,5.0,6.0), 
    labels=c("Citizen, born in the U.S.",
      "Citizen, naturalized",
      "Applicant for Naturalization",
      "Permanent Resident",
      "Applicant for Residence",
      "Other"))
  data$S4921000 <- factor(data$S4921000, 
    levels=c(1.0,2.0,3.0,4.0), 
    labels=c("MOST OF THE TIME",
      "SOME OF THE TIME",
      "ONLY NOW AND THEN",
      "HARDLY AT ALL"))
  data$S4921100 <- factor(data$S4921100, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DID NOT VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I THOUGHT ABOUT VOTING THIS TIME, BUT DIDN'T",
      "I USUALLY VOTE, BUT DIDN'T THIS TIME",
      "I AM SURE I VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$S4921400 <- factor(data$S4921400, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$S7509600 <- factor(data$S7509600, 
    levels=c(1.0,2.0,3.0,4.0,5.0,6.0), 
    labels=c("Citizen, born in the U.S.",
      "Citizen, naturalized",
      "Applicant for Naturalization",
      "Permanent Resident",
      "Applicant for Residence",
      "Other"))
  data$S7513700[-999999.0 <= data$S7513700 & data$S7513700 <= -3000.0] <- -999999.0
  data$S7513700[-2999.0 <= data$S7513700 & data$S7513700 <= -2000.0] <- -2999.0
  data$S7513700[-1999.0 <= data$S7513700 & data$S7513700 <= -1000.0] <- -1999.0
  data$S7513700[-999.0 <= data$S7513700 & data$S7513700 <= -1.0] <- -999.0
  data$S7513700[1.0 <= data$S7513700 & data$S7513700 <= 1000.0] <- 1.0
  data$S7513700[1001.0 <= data$S7513700 & data$S7513700 <= 2000.0] <- 1001.0
  data$S7513700[2001.0 <= data$S7513700 & data$S7513700 <= 3000.0] <- 2001.0
  data$S7513700[3001.0 <= data$S7513700 & data$S7513700 <= 5000.0] <- 3001.0
  data$S7513700[5001.0 <= data$S7513700 & data$S7513700 <= 10000.0] <- 5001.0
  data$S7513700[10001.0 <= data$S7513700 & data$S7513700 <= 20000.0] <- 10001.0
  data$S7513700[20001.0 <= data$S7513700 & data$S7513700 <= 30000.0] <- 20001.0
  data$S7513700[30001.0 <= data$S7513700 & data$S7513700 <= 40000.0] <- 30001.0
  data$S7513700[40001.0 <= data$S7513700 & data$S7513700 <= 50000.0] <- 40001.0
  data$S7513700[50001.0 <= data$S7513700 & data$S7513700 <= 65000.0] <- 50001.0
  data$S7513700[65001.0 <= data$S7513700 & data$S7513700 <= 80000.0] <- 65001.0
  data$S7513700[80001.0 <= data$S7513700 & data$S7513700 <= 100000.0] <- 80001.0
  data$S7513700[100001.0 <= data$S7513700 & data$S7513700 <= 150000.0] <- 100001.0
  data$S7513700[150001.0 <= data$S7513700 & data$S7513700 <= 200000.0] <- 150001.0
  data$S7513700[200001.0 <= data$S7513700 & data$S7513700 <= 999999.0] <- 200001.0
  data$S7513700 <- factor(data$S7513700, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$S7513900[20.0 <= data$S7513900 & data$S7513900 <= 99.0] <- 20.0
  data$S7513900 <- factor(data$S7513900, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$S8645400 <- factor(data$S8645400, 
    levels=c(1.0,2.0,3.0,4.0), 
    labels=c("MOST OF THE TIME",
      "SOME OF THE TIME",
      "ONLY NOW AND THEN",
      "HARDLY AT ALL"))
  data$S8645600 <- factor(data$S8645600, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DID NOT VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I THOUGHT ABOUT VOTING THIS TIME, BUT DIDN'T",
      "I USUALLY VOTE, BUT DIDN'T THIS TIME",
      "I AM SURE I VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$S8645700 <- factor(data$S8645700, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$S8645800 <- factor(data$S8645800, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$T2015800 <- factor(data$T2015800, 
    levels=c(1.0,2.0,3.0,4.0,5.0,6.0), 
    labels=c("Citizen, born in the U.S.",
      "Citizen, naturalized",
      "Applicant for Naturalization",
      "Permanent Resident",
      "Applicant for Residence",
      "Other"))
  data$T2016200[-999999.0 <= data$T2016200 & data$T2016200 <= -3000.0] <- -999999.0
  data$T2016200[-2999.0 <= data$T2016200 & data$T2016200 <= -2000.0] <- -2999.0
  data$T2016200[-1999.0 <= data$T2016200 & data$T2016200 <= -1000.0] <- -1999.0
  data$T2016200[-999.0 <= data$T2016200 & data$T2016200 <= -1.0] <- -999.0
  data$T2016200[1.0 <= data$T2016200 & data$T2016200 <= 1000.0] <- 1.0
  data$T2016200[1001.0 <= data$T2016200 & data$T2016200 <= 2000.0] <- 1001.0
  data$T2016200[2001.0 <= data$T2016200 & data$T2016200 <= 3000.0] <- 2001.0
  data$T2016200[3001.0 <= data$T2016200 & data$T2016200 <= 5000.0] <- 3001.0
  data$T2016200[5001.0 <= data$T2016200 & data$T2016200 <= 10000.0] <- 5001.0
  data$T2016200[10001.0 <= data$T2016200 & data$T2016200 <= 20000.0] <- 10001.0
  data$T2016200[20001.0 <= data$T2016200 & data$T2016200 <= 30000.0] <- 20001.0
  data$T2016200[30001.0 <= data$T2016200 & data$T2016200 <= 40000.0] <- 30001.0
  data$T2016200[40001.0 <= data$T2016200 & data$T2016200 <= 50000.0] <- 40001.0
  data$T2016200[50001.0 <= data$T2016200 & data$T2016200 <= 65000.0] <- 50001.0
  data$T2016200[65001.0 <= data$T2016200 & data$T2016200 <= 80000.0] <- 65001.0
  data$T2016200[80001.0 <= data$T2016200 & data$T2016200 <= 100000.0] <- 80001.0
  data$T2016200[100001.0 <= data$T2016200 & data$T2016200 <= 150000.0] <- 100001.0
  data$T2016200[150001.0 <= data$T2016200 & data$T2016200 <= 200000.0] <- 150001.0
  data$T2016200[200001.0 <= data$T2016200 & data$T2016200 <= 999999.0] <- 200001.0
  data$T2016200 <- factor(data$T2016200, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$T2016400[20.0 <= data$T2016400 & data$T2016400 <= 99.0] <- 20.0
  data$T2016400 <- factor(data$T2016400, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$T3161800 <- factor(data$T3161800, 
    levels=c(1.0,2.0,3.0,4.0), 
    labels=c("MOST OF THE TIME",
      "SOME OF THE TIME",
      "ONLY NOW AND THEN",
      "HARDLY AT ALL"))
  data$T3162000 <- factor(data$T3162000, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DID NOT VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I THOUGHT ABOUT VOTING THIS TIME, BUT DIDN'T",
      "I USUALLY VOTE, BUT DIDN'T THIS TIME",
      "I AM SURE I VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$T3162100 <- factor(data$T3162100, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$T3162200 <- factor(data$T3162200, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$T3162300 <- factor(data$T3162300, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DO NOT PLAN TO VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I DON'T KNOW IF I WILL VOTE OR NOT",
      "I PLAN TO VOTE",
      "I HAVE ALREADY VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$T5206500 <- factor(data$T5206500, 
    levels=c(1.0,2.0,3.0,4.0,5.0,6.0), 
    labels=c("Citizen, born in the U.S.",
      "Citizen, naturalized",
      "Applicant for Naturalization",
      "Permanent Resident",
      "Applicant for Residence",
      "Other"))
  data$T5206900[-999999.0 <= data$T5206900 & data$T5206900 <= -3000.0] <- -999999.0
  data$T5206900[-2999.0 <= data$T5206900 & data$T5206900 <= -2000.0] <- -2999.0
  data$T5206900[-1999.0 <= data$T5206900 & data$T5206900 <= -1000.0] <- -1999.0
  data$T5206900[-999.0 <= data$T5206900 & data$T5206900 <= -1.0] <- -999.0
  data$T5206900[1.0 <= data$T5206900 & data$T5206900 <= 1000.0] <- 1.0
  data$T5206900[1001.0 <= data$T5206900 & data$T5206900 <= 2000.0] <- 1001.0
  data$T5206900[2001.0 <= data$T5206900 & data$T5206900 <= 3000.0] <- 2001.0
  data$T5206900[3001.0 <= data$T5206900 & data$T5206900 <= 5000.0] <- 3001.0
  data$T5206900[5001.0 <= data$T5206900 & data$T5206900 <= 10000.0] <- 5001.0
  data$T5206900[10001.0 <= data$T5206900 & data$T5206900 <= 20000.0] <- 10001.0
  data$T5206900[20001.0 <= data$T5206900 & data$T5206900 <= 30000.0] <- 20001.0
  data$T5206900[30001.0 <= data$T5206900 & data$T5206900 <= 40000.0] <- 30001.0
  data$T5206900[40001.0 <= data$T5206900 & data$T5206900 <= 50000.0] <- 40001.0
  data$T5206900[50001.0 <= data$T5206900 & data$T5206900 <= 65000.0] <- 50001.0
  data$T5206900[65001.0 <= data$T5206900 & data$T5206900 <= 80000.0] <- 65001.0
  data$T5206900[80001.0 <= data$T5206900 & data$T5206900 <= 100000.0] <- 80001.0
  data$T5206900[100001.0 <= data$T5206900 & data$T5206900 <= 150000.0] <- 100001.0
  data$T5206900[150001.0 <= data$T5206900 & data$T5206900 <= 200000.0] <- 150001.0
  data$T5206900[200001.0 <= data$T5206900 & data$T5206900 <= 999999.0] <- 200001.0
  data$T5206900 <- factor(data$T5206900, 
    levels=c(-999999.0,-2999.0,-1999.0,-999.0,0.0,1.0,1001.0,2001.0,3001.0,5001.0,10001.0,20001.0,30001.0,40001.0,50001.0,65001.0,80001.0,100001.0,150001.0,200001.0), 
    labels=c("-999999 TO -3000: < -2999",
      "-2999 TO -2000",
      "-1999 TO -1000",
      "-999 TO -1",
      "0",
      "1 TO 1000",
      "1001 TO 2000",
      "2001 TO 3000",
      "3001 TO 5000",
      "5001 TO 10000",
      "10001 TO 20000",
      "20001 TO 30000",
      "30001 TO 40000",
      "40001 TO 50000",
      "50001 TO 65000",
      "65001 TO 80000",
      "80001 TO 100000",
      "100001 TO 150000",
      "150001 TO 200000",
      "200001 TO 999999: 200001+"))
  data$T5207100[20.0 <= data$T5207100 & data$T5207100 <= 99.0] <- 20.0
  data$T5207100 <- factor(data$T5207100, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0), 
    labels=c("0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "10",
      "11",
      "12",
      "13",
      "14",
      "15",
      "16",
      "17",
      "18",
      "19",
      "20 TO 99: 20+"))
  data$T6215300 <- factor(data$T6215300, 
    levels=c(1.0,2.0,3.0,4.0), 
    labels=c("MOST OF THE TIME",
      "SOME OF THE TIME",
      "ONLY NOW AND THEN",
      "HARDLY AT ALL"))
  data$T6215500 <- factor(data$T6215500, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DID NOT VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I THOUGHT ABOUT VOTING THIS TIME, BUT DIDN'T",
      "I USUALLY VOTE, BUT DIDN'T THIS TIME",
      "I AM SURE I VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$T6215600 <- factor(data$T6215600, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$T6215700 <- factor(data$T6215700, 
    levels=c(0.0,1.0), 
    labels=c("NO",
      "YES"))
  data$T6215800 <- factor(data$T6215800, 
    levels=c(1.0,2.0,3.0,4.0,5.0), 
    labels=c("I DO NOT PLAN TO VOTE (IN THE ELECTION THIS NOVEMBER)",
      "I DON'T KNOW IF I WILL VOTE OR NOT",
      "I PLAN TO VOTE",
      "I HAVE ALREADY VOTED",
      "R NOT ELIGIBLE TO VOTE"))
  data$Z9061400[1.0 <= data$Z9061400 & data$Z9061400 <= 5.0] <- 1.0
  data$Z9061400[6.0 <= data$Z9061400 & data$Z9061400 <= 10.0] <- 6.0
  data$Z9061400[11.0 <= data$Z9061400 & data$Z9061400 <= 15.0] <- 11.0
  data$Z9061400[16.0 <= data$Z9061400 & data$Z9061400 <= 20.0] <- 16.0
  data$Z9061400[21.0 <= data$Z9061400 & data$Z9061400 <= 25.0] <- 21.0
  data$Z9061400[26.0 <= data$Z9061400 & data$Z9061400 <= 30.0] <- 26.0
  data$Z9061400[31.0 <= data$Z9061400 & data$Z9061400 <= 35.0] <- 31.0
  data$Z9061400[36.0 <= data$Z9061400 & data$Z9061400 <= 40.0] <- 36.0
  data$Z9061400[41.0 <= data$Z9061400 & data$Z9061400 <= 45.0] <- 41.0
  data$Z9061400[46.0 <= data$Z9061400 & data$Z9061400 <= 50.0] <- 46.0
  data$Z9061400[51.0 <= data$Z9061400 & data$Z9061400 <= 999.0] <- 51.0
  data$Z9061400 <- factor(data$Z9061400, 
    levels=c(0.0,1.0,6.0,11.0,16.0,21.0,26.0,31.0,36.0,41.0,46.0,51.0), 
    labels=c("0: weeks",
      "1 TO 5: weeks",
      "6 TO 10: weeks",
      "11 TO 15: weeks",
      "16 TO 20: weeks",
      "21 TO 25: weeks",
      "26 TO 30: weeks",
      "31 TO 35: weeks",
      "36 TO 40: weeks",
      "41 TO 45: weeks",
      "46 TO 50: weeks",
      "51 TO 999: weeks"))
  data$Z9061600[1.0 <= data$Z9061600 & data$Z9061600 <= 5.0] <- 1.0
  data$Z9061600[6.0 <= data$Z9061600 & data$Z9061600 <= 10.0] <- 6.0
  data$Z9061600[11.0 <= data$Z9061600 & data$Z9061600 <= 15.0] <- 11.0
  data$Z9061600[16.0 <= data$Z9061600 & data$Z9061600 <= 20.0] <- 16.0
  data$Z9061600[21.0 <= data$Z9061600 & data$Z9061600 <= 25.0] <- 21.0
  data$Z9061600[26.0 <= data$Z9061600 & data$Z9061600 <= 30.0] <- 26.0
  data$Z9061600[31.0 <= data$Z9061600 & data$Z9061600 <= 35.0] <- 31.0
  data$Z9061600[36.0 <= data$Z9061600 & data$Z9061600 <= 40.0] <- 36.0
  data$Z9061600[41.0 <= data$Z9061600 & data$Z9061600 <= 45.0] <- 41.0
  data$Z9061600[46.0 <= data$Z9061600 & data$Z9061600 <= 50.0] <- 46.0
  data$Z9061600[51.0 <= data$Z9061600 & data$Z9061600 <= 999.0] <- 51.0
  data$Z9061600 <- factor(data$Z9061600, 
    levels=c(0.0,1.0,6.0,11.0,16.0,21.0,26.0,31.0,36.0,41.0,46.0,51.0), 
    labels=c("0: weeks",
      "1 TO 5: weeks",
      "6 TO 10: weeks",
      "11 TO 15: weeks",
      "16 TO 20: weeks",
      "21 TO 25: weeks",
      "26 TO 30: weeks",
      "31 TO 35: weeks",
      "36 TO 40: weeks",
      "41 TO 45: weeks",
      "46 TO 50: weeks",
      "51 TO 999: weeks"))
  data$Z9061800[1.0 <= data$Z9061800 & data$Z9061800 <= 5.0] <- 1.0
  data$Z9061800[6.0 <= data$Z9061800 & data$Z9061800 <= 10.0] <- 6.0
  data$Z9061800[11.0 <= data$Z9061800 & data$Z9061800 <= 15.0] <- 11.0
  data$Z9061800[16.0 <= data$Z9061800 & data$Z9061800 <= 20.0] <- 16.0
  data$Z9061800[21.0 <= data$Z9061800 & data$Z9061800 <= 25.0] <- 21.0
  data$Z9061800[26.0 <= data$Z9061800 & data$Z9061800 <= 30.0] <- 26.0
  data$Z9061800[31.0 <= data$Z9061800 & data$Z9061800 <= 35.0] <- 31.0
  data$Z9061800[36.0 <= data$Z9061800 & data$Z9061800 <= 40.0] <- 36.0
  data$Z9061800[41.0 <= data$Z9061800 & data$Z9061800 <= 45.0] <- 41.0
  data$Z9061800[46.0 <= data$Z9061800 & data$Z9061800 <= 50.0] <- 46.0
  data$Z9061800[51.0 <= data$Z9061800 & data$Z9061800 <= 999.0] <- 51.0
  data$Z9061800 <- factor(data$Z9061800, 
    levels=c(0.0,1.0,6.0,11.0,16.0,21.0,26.0,31.0,36.0,41.0,46.0,51.0), 
    labels=c("0: weeks",
      "1 TO 5: weeks",
      "6 TO 10: weeks",
      "11 TO 15: weeks",
      "16 TO 20: weeks",
      "21 TO 25: weeks",
      "26 TO 30: weeks",
      "31 TO 35: weeks",
      "36 TO 40: weeks",
      "41 TO 45: weeks",
      "46 TO 50: weeks",
      "51 TO 999: weeks"))
  data$Z9061901[1.0 <= data$Z9061901 & data$Z9061901 <= 5.0] <- 1.0
  data$Z9061901[6.0 <= data$Z9061901 & data$Z9061901 <= 10.0] <- 6.0
  data$Z9061901[11.0 <= data$Z9061901 & data$Z9061901 <= 15.0] <- 11.0
  data$Z9061901[16.0 <= data$Z9061901 & data$Z9061901 <= 20.0] <- 16.0
  data$Z9061901[21.0 <= data$Z9061901 & data$Z9061901 <= 25.0] <- 21.0
  data$Z9061901[26.0 <= data$Z9061901 & data$Z9061901 <= 30.0] <- 26.0
  data$Z9061901[31.0 <= data$Z9061901 & data$Z9061901 <= 35.0] <- 31.0
  data$Z9061901[36.0 <= data$Z9061901 & data$Z9061901 <= 40.0] <- 36.0
  data$Z9061901[41.0 <= data$Z9061901 & data$Z9061901 <= 45.0] <- 41.0
  data$Z9061901[46.0 <= data$Z9061901 & data$Z9061901 <= 50.0] <- 46.0
  data$Z9061901[51.0 <= data$Z9061901 & data$Z9061901 <= 999.0] <- 51.0
  data$Z9061901 <- factor(data$Z9061901, 
    levels=c(0.0,1.0,6.0,11.0,16.0,21.0,26.0,31.0,36.0,41.0,46.0,51.0), 
    labels=c("0: weeks",
      "1 TO 5: weeks",
      "6 TO 10: weeks",
      "11 TO 15: weeks",
      "16 TO 20: weeks",
      "21 TO 25: weeks",
      "26 TO 30: weeks",
      "31 TO 35: weeks",
      "36 TO 40: weeks",
      "41 TO 45: weeks",
      "46 TO 50: weeks",
      "51 TO 999: weeks"))
  data$Z9065201[0.0 <= data$Z9065201 & data$Z9065201 <= 50.0] <- 0.0
  data$Z9065201[51.0 <= data$Z9065201 & data$Z9065201 <= 100.0] <- 51.0
  data$Z9065201[101.0 <= data$Z9065201 & data$Z9065201 <= 150.0] <- 101.0
  data$Z9065201[151.0 <= data$Z9065201 & data$Z9065201 <= 200.0] <- 151.0
  data$Z9065201[201.0 <= data$Z9065201 & data$Z9065201 <= 250.0] <- 201.0
  data$Z9065201[251.0 <= data$Z9065201 & data$Z9065201 <= 300.0] <- 251.0
  data$Z9065201[301.0 <= data$Z9065201 & data$Z9065201 <= 350.0] <- 301.0
  data$Z9065201[351.0 <= data$Z9065201 & data$Z9065201 <= 400.0] <- 351.0
  data$Z9065201[401.0 <= data$Z9065201 & data$Z9065201 <= 450.0] <- 401.0
  data$Z9065201[451.0 <= data$Z9065201 & data$Z9065201 <= 500.0] <- 451.0
  data$Z9065201[501.0 <= data$Z9065201 & data$Z9065201 <= 550.0] <- 501.0
  data$Z9065201[551.0 <= data$Z9065201 & data$Z9065201 <= 600.0] <- 551.0
  data$Z9065201[601.0 <= data$Z9065201 & data$Z9065201 <= 650.0] <- 601.0
  data$Z9065201[651.0 <= data$Z9065201 & data$Z9065201 <= 700.0] <- 651.0
  data$Z9065201[701.0 <= data$Z9065201 & data$Z9065201 <= 750.0] <- 701.0
  data$Z9065201[751.0 <= data$Z9065201 & data$Z9065201 <= 800.0] <- 751.0
  data$Z9065201[801.0 <= data$Z9065201 & data$Z9065201 <= 850.0] <- 801.0
  data$Z9065201[851.0 <= data$Z9065201 & data$Z9065201 <= 900.0] <- 851.0
  data$Z9065201[901.0 <= data$Z9065201 & data$Z9065201 <= 950.0] <- 901.0
  data$Z9065201[951.0 <= data$Z9065201 & data$Z9065201 <= 1000.0] <- 951.0
  data$Z9065201[1001.0 <= data$Z9065201 & data$Z9065201 <= 1050.0] <- 1001.0
  data$Z9065201[1051.0 <= data$Z9065201 & data$Z9065201 <= 1100.0] <- 1051.0
  data$Z9065201[1101.0 <= data$Z9065201 & data$Z9065201 <= 1150.0] <- 1101.0
  data$Z9065201[1151.0 <= data$Z9065201 & data$Z9065201 <= 1200.0] <- 1151.0
  data$Z9065201[1201.0 <= data$Z9065201 & data$Z9065201 <= 1250.0] <- 1201.0
  data$Z9065201[1251.0 <= data$Z9065201 & data$Z9065201 <= 1300.0] <- 1251.0
  data$Z9065201 <- factor(data$Z9065201, 
    levels=c(0.0,51.0,101.0,151.0,201.0,251.0,301.0,351.0,401.0,451.0,501.0,551.0,601.0,651.0,701.0,751.0,801.0,851.0,901.0,951.0,1001.0,1051.0,1101.0,1151.0,1201.0,1251.0), 
    labels=c("0 TO 50: weeks",
      "51 TO 100: weeks",
      "101 TO 150: weeks",
      "151 TO 200: weeks",
      "201 TO 250: weeks",
      "251 TO 300: weeks",
      "301 TO 350: weeks",
      "351 TO 400: weeks",
      "401 TO 450: weeks",
      "451 TO 500: weeks",
      "501 TO 550: weeks",
      "551 TO 600: weeks",
      "601 TO 650: weeks",
      "651 TO 700: weeks",
      "701 TO 750: weeks",
      "751 TO 800: weeks",
      "801 TO 850: weeks",
      "851 TO 900: weeks",
      "901 TO 950: weeks",
      "951 TO 1000: weeks",
      "1001 TO 1050: weeks",
      "1051 TO 1100: weeks",
      "1101 TO 1150: weeks",
      "1151 TO 1200: weeks",
      "1201 TO 1250: weeks",
      "1251 TO 1300: weeks"))
  data$Z9065301[0.0 <= data$Z9065301 & data$Z9065301 <= 50.0] <- 0.0
  data$Z9065301[51.0 <= data$Z9065301 & data$Z9065301 <= 100.0] <- 51.0
  data$Z9065301[101.0 <= data$Z9065301 & data$Z9065301 <= 150.0] <- 101.0
  data$Z9065301[151.0 <= data$Z9065301 & data$Z9065301 <= 200.0] <- 151.0
  data$Z9065301[201.0 <= data$Z9065301 & data$Z9065301 <= 250.0] <- 201.0
  data$Z9065301[251.0 <= data$Z9065301 & data$Z9065301 <= 300.0] <- 251.0
  data$Z9065301[301.0 <= data$Z9065301 & data$Z9065301 <= 350.0] <- 301.0
  data$Z9065301[351.0 <= data$Z9065301 & data$Z9065301 <= 400.0] <- 351.0
  data$Z9065301[401.0 <= data$Z9065301 & data$Z9065301 <= 450.0] <- 401.0
  data$Z9065301[451.0 <= data$Z9065301 & data$Z9065301 <= 500.0] <- 451.0
  data$Z9065301[501.0 <= data$Z9065301 & data$Z9065301 <= 550.0] <- 501.0
  data$Z9065301[551.0 <= data$Z9065301 & data$Z9065301 <= 600.0] <- 551.0
  data$Z9065301[601.0 <= data$Z9065301 & data$Z9065301 <= 650.0] <- 601.0
  data$Z9065301[651.0 <= data$Z9065301 & data$Z9065301 <= 700.0] <- 651.0
  data$Z9065301[701.0 <= data$Z9065301 & data$Z9065301 <= 750.0] <- 701.0
  data$Z9065301[751.0 <= data$Z9065301 & data$Z9065301 <= 800.0] <- 751.0
  data$Z9065301[801.0 <= data$Z9065301 & data$Z9065301 <= 850.0] <- 801.0
  data$Z9065301[851.0 <= data$Z9065301 & data$Z9065301 <= 900.0] <- 851.0
  data$Z9065301[901.0 <= data$Z9065301 & data$Z9065301 <= 950.0] <- 901.0
  data$Z9065301[951.0 <= data$Z9065301 & data$Z9065301 <= 1000.0] <- 951.0
  data$Z9065301[1001.0 <= data$Z9065301 & data$Z9065301 <= 1050.0] <- 1001.0
  data$Z9065301[1051.0 <= data$Z9065301 & data$Z9065301 <= 1100.0] <- 1051.0
  data$Z9065301[1101.0 <= data$Z9065301 & data$Z9065301 <= 1150.0] <- 1101.0
  data$Z9065301[1151.0 <= data$Z9065301 & data$Z9065301 <= 1200.0] <- 1151.0
  data$Z9065301[1201.0 <= data$Z9065301 & data$Z9065301 <= 1250.0] <- 1201.0
  data$Z9065301[1251.0 <= data$Z9065301 & data$Z9065301 <= 1300.0] <- 1251.0
  data$Z9065301 <- factor(data$Z9065301, 
    levels=c(0.0,51.0,101.0,151.0,201.0,251.0,301.0,351.0,401.0,451.0,501.0,551.0,601.0,651.0,701.0,751.0,801.0,851.0,901.0,951.0,1001.0,1051.0,1101.0,1151.0,1201.0,1251.0), 
    labels=c("0 TO 50: weeks",
      "51 TO 100: weeks",
      "101 TO 150: weeks",
      "151 TO 200: weeks",
      "201 TO 250: weeks",
      "251 TO 300: weeks",
      "301 TO 350: weeks",
      "351 TO 400: weeks",
      "401 TO 450: weeks",
      "451 TO 500: weeks",
      "501 TO 550: weeks",
      "551 TO 600: weeks",
      "601 TO 650: weeks",
      "651 TO 700: weeks",
      "701 TO 750: weeks",
      "751 TO 800: weeks",
      "801 TO 850: weeks",
      "851 TO 900: weeks",
      "901 TO 950: weeks",
      "951 TO 1000: weeks",
      "1001 TO 1050: weeks",
      "1051 TO 1100: weeks",
      "1101 TO 1150: weeks",
      "1151 TO 1200: weeks",
      "1201 TO 1250: weeks",
      "1251 TO 1300: weeks"))
  data$Z9065401[0.0 <= data$Z9065401 & data$Z9065401 <= 50.0] <- 0.0
  data$Z9065401[51.0 <= data$Z9065401 & data$Z9065401 <= 100.0] <- 51.0
  data$Z9065401[101.0 <= data$Z9065401 & data$Z9065401 <= 150.0] <- 101.0
  data$Z9065401[151.0 <= data$Z9065401 & data$Z9065401 <= 200.0] <- 151.0
  data$Z9065401[201.0 <= data$Z9065401 & data$Z9065401 <= 250.0] <- 201.0
  data$Z9065401[251.0 <= data$Z9065401 & data$Z9065401 <= 300.0] <- 251.0
  data$Z9065401[301.0 <= data$Z9065401 & data$Z9065401 <= 350.0] <- 301.0
  data$Z9065401[351.0 <= data$Z9065401 & data$Z9065401 <= 400.0] <- 351.0
  data$Z9065401[401.0 <= data$Z9065401 & data$Z9065401 <= 450.0] <- 401.0
  data$Z9065401[451.0 <= data$Z9065401 & data$Z9065401 <= 500.0] <- 451.0
  data$Z9065401[501.0 <= data$Z9065401 & data$Z9065401 <= 550.0] <- 501.0
  data$Z9065401[551.0 <= data$Z9065401 & data$Z9065401 <= 600.0] <- 551.0
  data$Z9065401[601.0 <= data$Z9065401 & data$Z9065401 <= 650.0] <- 601.0
  data$Z9065401[651.0 <= data$Z9065401 & data$Z9065401 <= 700.0] <- 651.0
  data$Z9065401[701.0 <= data$Z9065401 & data$Z9065401 <= 750.0] <- 701.0
  data$Z9065401[751.0 <= data$Z9065401 & data$Z9065401 <= 800.0] <- 751.0
  data$Z9065401[801.0 <= data$Z9065401 & data$Z9065401 <= 850.0] <- 801.0
  data$Z9065401[851.0 <= data$Z9065401 & data$Z9065401 <= 900.0] <- 851.0
  data$Z9065401[901.0 <= data$Z9065401 & data$Z9065401 <= 950.0] <- 901.0
  data$Z9065401[951.0 <= data$Z9065401 & data$Z9065401 <= 1000.0] <- 951.0
  data$Z9065401[1001.0 <= data$Z9065401 & data$Z9065401 <= 1050.0] <- 1001.0
  data$Z9065401[1051.0 <= data$Z9065401 & data$Z9065401 <= 1100.0] <- 1051.0
  data$Z9065401[1101.0 <= data$Z9065401 & data$Z9065401 <= 1150.0] <- 1101.0
  data$Z9065401[1151.0 <= data$Z9065401 & data$Z9065401 <= 1200.0] <- 1151.0
  data$Z9065401[1201.0 <= data$Z9065401 & data$Z9065401 <= 1250.0] <- 1201.0
  data$Z9065401[1251.0 <= data$Z9065401 & data$Z9065401 <= 1300.0] <- 1251.0
  data$Z9065401 <- factor(data$Z9065401, 
    levels=c(0.0,51.0,101.0,151.0,201.0,251.0,301.0,351.0,401.0,451.0,501.0,551.0,601.0,651.0,701.0,751.0,801.0,851.0,901.0,951.0,1001.0,1051.0,1101.0,1151.0,1201.0,1251.0), 
    labels=c("0 TO 50: weeks",
      "51 TO 100: weeks",
      "101 TO 150: weeks",
      "151 TO 200: weeks",
      "201 TO 250: weeks",
      "251 TO 300: weeks",
      "301 TO 350: weeks",
      "351 TO 400: weeks",
      "401 TO 450: weeks",
      "451 TO 500: weeks",
      "501 TO 550: weeks",
      "551 TO 600: weeks",
      "601 TO 650: weeks",
      "651 TO 700: weeks",
      "701 TO 750: weeks",
      "751 TO 800: weeks",
      "801 TO 850: weeks",
      "851 TO 900: weeks",
      "901 TO 950: weeks",
      "951 TO 1000: weeks",
      "1001 TO 1050: weeks",
      "1051 TO 1100: weeks",
      "1101 TO 1150: weeks",
      "1151 TO 1200: weeks",
      "1201 TO 1250: weeks",
      "1251 TO 1300: weeks"))
  data$Z9083800 <- factor(data$Z9083800, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,95.0), 
    labels=c("None",
      "1st grade",
      "2nd grade",
      "3rd grade",
      "4th grade",
      "5th grade",
      "6th grade",
      "7th grade",
      "8th grade",
      "9th grade",
      "10th grade",
      "11th grade",
      "12th grade",
      "1st year college",
      "2nd year college",
      "3rd year college",
      "4th year college",
      "5th year college",
      "6th year college",
      "7th year college",
      "8th year college or more",
      "Ungraded"))
  data$Z9083900 <- factor(data$Z9083900, 
    levels=c(0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0), 
    labels=c("None",
      "GED",
      "High school diploma (Regular 12 year program)",
      "Associate/Junior college (AA)",
      "Bachelor's degree (BA, BS)",
      "Master's degree (MA, MS)",
      "PhD",
      "Professional degree (DDS, JD, MD)"))
  return(data)
}

varlabels <- c("PUBID - YTH ID CODE 1997",
  "YOUTH ADOPDADID (ROS ITEM) L1 1997",
  "YOUTH ADOPMOMID (ROS ITEM) L1 1997",
  "YOUTH DADID (ROS ITEM) L1 1997",
  "YOUTH FOSTDADID (ROS ITEM) L1 1997",
  "YOUTH FOSTMOMID (ROS ITEM) L1 1997",
  "YOUTH MOMID (ROS ITEM) L1 1997",
  "YOUTH PARENTID (ROS ITEM) L1 1997",
  "KEY!SEX (SYMBOL) 1997",
  "KEY!BDATE M/Y (SYMBOL) 1997",
  "KEY!BDATE M/Y (SYMBOL) 1997",
  "CV_CITIZENSHIP 1997",
  "CV_INCOME_GROSS_YR 1997",
  "CV_HH_INCOME_SOURCE 1997",
  "CV_HH_SIZE 1997",
  "CV_SAMPLE_TYPE 1997",
  "CV_HGC_BIO_DAD 1997",
  "CV_HGC_BIO_MOM 1997",
  "CV_HGC_RES_DAD 1997",
  "CV_HGC_RES_MOM 1997",
  "KEY!RACE_ETHNICITY (SYMBOL) 1997",
  "CV_INCOME_GROSS_YR 1998",
  "CV_HH_SIZE 1998",
  "CV_INCOME_GROSS_YR 1999",
  "CV_HH_SIZE 1999",
  "CV_INCOME_GROSS_YR 2000",
  "CV_HH_SIZE 2000",
  "CV_INCOME_GROSS_YR 2001",
  "CV_HH_SIZE 2001",
  "CV_INCOME_GROSS_YR 2002",
  "CV_HH_SIZE 2002",
  "CV_INCOME_GROSS_YR 2003",
  "CV_HH_SIZE 2003",
  "CV_INCOME_FAMILY 2004",
  "CV_HH_SIZE 2004",
  "CV_CITIZENSHIP_CURR 2004",
  "INTEREST IN GOVT AND PUB AFFAIRS 2004",
  "DID R VOTE IN NOVEMBER, 2004? 2004",
  "R REGISTERED TO VOTE IN 2004? 2004",
  "CV_CITIZENSHIP_CURR 2006",
  "CV_INCOME_FAMILY 2006",
  "CV_HH_SIZE 2006",
  "INTEREST IN GOVT AND PUB AFFAIRS 2006",
  "DID R VOTE IN NOVEMBER, 2006? 2006",
  "R REGISTERED TO VOTE IN 2006 (RETRO)? 2006",
  "R REGISTERED TO VOTE IN 2006 (PRO)? 2006",
  "CV_CITIZENSHIP_CURR 2008",
  "CV_INCOME_FAMILY 2008",
  "CV_HH_SIZE 2008",
  "INTEREST IN GOVT AND PUB AFFAIRS 2008",
  "DID R VOTE IN NOVEMBER, 2008? 2008",
  "R REGISTERED TO VOTE IN 2008 (RETRO)? 2008",
  "R REGISTERED TO VOTE IN 2008 (PRO)? 2008",
  "R REGISTERED TO VOTE IN 2008 (PRO)? 2008",
  "CV_CITIZENSHIP_CURR 2010",
  "CV_INCOME_FAMILY 2010",
  "CV_HH_SIZE 2010",
  "INTEREST IN GOVT AND PUB AFFAIRS 2010",
  "DID R VOTE IN NOVEMBER, 2010? 2010",
  "R REGISTERED TO VOTE IN 2010 (RETRO)? 2010",
  "R REGISTERED TO VOTE IN 2010 (PRO)? 2010",
  "R REGISTERED TO VOTE IN 2010 (PRO)? 2010",
  "CVC_WKSWK_YR_ALL L4",
  "CVC_WKSWK_YR_ALL L6",
  "CVC_WKSWK_YR_ALL L8",
  "CVC_WKSWK_YR_ALL L10",
  "CVC_WKSWK_TEEN",
  "CVC_WKSWK_ADULT_ET",
  "CVC_WKSWK_ADULT_ALL",
  "CVC_HGC_EVER",
  "CVC_HIGHEST_DEGREE_EVER"
)


# Use qnames rather than rnums

qnames = function(data) {
  names(data) <- c("PUBID_1997",
    "YOUTH_ADOPDADID.01_1997",
    "YOUTH_ADOPMOMID.01_1997",
    "YOUTH_DADID.01_1997",
    "YOUTH_FOSTDADID.01_1997",
    "YOUTH_FOSTMOMID.01_1997",
    "YOUTH_MOMID.01_1997",
    "YOUTH_PARENTID.01_1997",
    "KEY_SEX_1997",
    "KEY_BDATE_M_1997",
    "KEY_BDATE_Y_1997",
    "CV_CITIZENSHIP_1997",
    "CV_INCOME_GROSS_YR_1997",
    "CV_HH_INCOME_SOURCE_1997",
    "CV_HH_SIZE_1997",
    "CV_SAMPLE_TYPE_1997",
    "CV_HGC_BIO_DAD_1997",
    "CV_HGC_BIO_MOM_1997",
    "CV_HGC_RES_DAD_1997",
    "CV_HGC_RES_MOM_1997",
    "KEY_RACE_ETHNICITY_1997",
    "CV_INCOME_GROSS_YR_1998",
    "CV_HH_SIZE_1998",
    "CV_INCOME_GROSS_YR_1999",
    "CV_HH_SIZE_1999",
    "CV_INCOME_GROSS_YR_2000",
    "CV_HH_SIZE_2000",
    "CV_INCOME_GROSS_YR_2001",
    "CV_HH_SIZE_2001",
    "CV_INCOME_GROSS_YR_2002",
    "CV_HH_SIZE_2002",
    "CV_INCOME_GROSS_YR_2003",
    "CV_HH_SIZE_2003",
    "CV_INCOME_FAMILY_2004",
    "CV_HH_SIZE_2004",
    "CV_CITIZEN_CURRENT_2004",
    "YPOL-105_2004",
    "YPOL-110_2004",
    "YPOL-130_2004",
    "CV_CITIZEN_CURRENT_2006",
    "CV_INCOME_FAMILY_2006",
    "CV_HH_SIZE_2006",
    "YPOL-105_2006",
    "YPOL-110_2006",
    "YPOL-130_2006",
    "YPOL-130A_2006",
    "CV_CITIZEN_CURRENT_2008",
    "CV_INCOME_FAMILY_2008",
    "CV_HH_SIZE_2008",
    "YPOL-105_2008",
    "YPOL-110_2008",
    "YPOL-130_2008",
    "YPOL-130A_2008",
    "YPOL-130B_2008",
    "CV_CITIZEN_CURRENT_2010",
    "CV_INCOME_FAMILY_2010",
    "CV_HH_SIZE_2010",
    "YPOL-105_2010",
    "YPOL-110_2010",
    "YPOL-130_2010",
    "YPOL-130A_2010",
    "YPOL-130B_2010",
    "CVC_WKSWK_YR_ALL.04_XRND",
    "CVC_WKSWK_YR_ALL.06_XRND",
    "CVC_WKSWK_YR_ALL.08_XRND",
    "CVC_WKSWK_YR_ALL.10_XRND",
    "CVC_WKSWK_TEEN2_XRND",
    "CVC_WKSWK_ADULT2_ET_XRND",
    "CVC_WKSWK_ADULT2_ALL_XRND",
    "CVC_HGC_EVER_XRND",
    "CVC_HIGHEST_DEGREE_EVER_XRND")
  return(data)
}


write_stata(new_data, "nlsy97_raw.dta", version = 13)


#********************************************************************************************************

# Remove the '#' before the following line to create a data file called "categories" with value labels. 
#categories <- vallabels(new_data)

# Remove the '#' before the following lines to rename variables using Qnames instead of Reference Numbers
#new_data <- qnames(new_data)
#categories <- qnames(categories)

# Produce summaries for the raw (uncategorized) data file
summary(new_data)

# Remove the '#' before the following lines to produce summaries for the "categories" data file.
#categories <- vallabels(new_data)
#summary(categories)

#************************************************************************************************************

